package com.googlecode.pwlodars.piteststat.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
import org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

import com.googlecode.pwlodars.piteststat.database.PitResultDao;
import com.googlecode.pwlodars.piteststat.infrastructure.ForwardToViewController;
import com.googlecode.pwlodars.piteststat.statistics.AveragesCalculkator;
import com.googlecode.pwlodars.piteststat.statistics.StatisticsControler;

@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{

	@Bean
	ViewResolver viewResolver() {
		final UrlBasedViewResolver resolver = new UrlBasedViewResolver();
		resolver.setPrefix("/WEB-INF/jsp/");
		resolver.setSuffix(".jsp");
		resolver.setViewClass(JstlView.class);
		return resolver;
	}
	
	@Bean
	AveragesCalculkator averagesCalculkator(){
		return new AveragesCalculkator();
	}
	
	@Bean
	@Autowired
	StatisticsControler statisticsControler(PitResultDao pitResultDao,AveragesCalculkator averagesCalculkator){
		return new StatisticsControler(pitResultDao,averagesCalculkator);
	}
	
	@Bean
	DefaultAnnotationHandlerMapping defaultAnnotationHandlerMapping(){
		return new DefaultAnnotationHandlerMapping();
	}
	
	@Bean
	AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter(){
		return new AnnotationMethodHandlerAdapter();
	}

	
	@Bean
	public ForwardToViewController forwardToViewController(){
		return new ForwardToViewController();
	}
	
}
